package TCPSocket;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class SocketTCP04Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(), 8888);
        OutputStream outputStream = socket.getOutputStream();
        InputStream inputStream = socket.getInputStream();
        String filePath = "e:\\image.png";
        FileInputStream fileInputStream = new FileInputStream(filePath);

        byte buf[] = new byte[1024];
        int readLen = 0;
        while ((readLen = fileInputStream.read(buf)) != -1){
            outputStream.write(buf,0,readLen);
        }
        socket.shutdownOutput();


        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        String s = br.readLine();
        System.out.println(s);

        //4.关闭对应的流和socket(必须)
        br.close();
        outputStream.close();
        fileInputStream.close();
        socket.close();
    }
}
